package com.cater.project.service;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cater.common.BaseEntity;
import com.cater.common.PageResult;
import com.cater.project.dao.DemandPersonalDao;
import com.cater.project.entity.DemandPersonal;
import com.cater.query.CommonQuery;
import com.cater.sys.service.BaseService;

/**
 * @author yong
 * @Date 2018年3月23日-上午10:57:20
 * @项目管理业务层
 */
@Service
public class DemandPersonalService implements BaseService<DemandPersonal, CommonQuery, String> {

	@Autowired
	DemandPersonalDao dao;
	
	@Override
	public PageResult<DemandPersonal> findPageResult(CommonQuery query) {
		PageResult<DemandPersonal> result = new PageResult<DemandPersonal>();
		result.setPage(query.getPage());
		result.setPageSize(query.getRows());
		int count = dao.findCount(query);
		int first = (query.getPage() - 1) * query.getRows();
		int max = query.getRows();
		List<DemandPersonal> list = dao.findList(query, first, max);
		result.setRows(list);
		result.setRecords(count);
		return result;
	}

	@Override
	public List<DemandPersonal> getAll() {
		return dao.getAll();
	}

	@Override
	public List<DemandPersonal> getAllCommon(CommonQuery query) {
		return dao.getAllCommon(query);
	}

	@Override
	public int save(DemandPersonal t) {
		return dao.save(t);
	}

	@Override
	public String saves(DemandPersonal t) {
		t.setId(UUID.randomUUID().toString().replaceAll("-", ""));
		BaseEntity.getCreate(t);
		dao.save(t);
		return t.getId();
	}

	@Override
	public void update(DemandPersonal t) {
		BaseEntity.getupdate(t);
		dao.update(t);
	}

	@Override
	public void delete(String id) {
		dao.delete(id);
	}

	@Override
	public DemandPersonal getById(String id) {
		return dao.getById(id);
	}

}
